package cn.wolfcode.edu.service.impl;

import cn.wolfcode.edu.domain.Employee;
import cn.wolfcode.edu.domain.Test;
import cn.wolfcode.edu.mapper.TestMapper;
import cn.wolfcode.edu.query.TestQueryObject;
import cn.wolfcode.edu.service.ITestService;
import cn.wolfcode.edu.util.PageResult;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Service
public class TestServiceImpl implements ITestService {

    @Autowired
    private TestMapper testMapper;

    public void save(Test test) {
        testMapper.insert(test);
    }

    public PageResult query(TestQueryObject qo) {
        //查询数据数
        Integer total = testMapper.queryForCount(qo);
        //查询数据集
        List<Test> rows =  testMapper.queryForList(qo);
        return new PageResult(total,rows);
    }

    public void audit(Test test) {
        //保存当前批阅人
        Employee employee = (Employee) SecurityUtils.getSubject().getPrincipal();
        test.setHandler(employee);
        testMapper.audit(test);
    }

    public void delete(Long testId) {
        testMapper.deleteByPrimaryKey(testId);
    }
}
